package com.notary.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.notary.entity.vo.JsonResult;
import com.notary.mapper.SocketMsgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import  com.notary.service.SocketMsgService;
import com.notary.entity.SocketMsg;

import javax.servlet.http.HttpServletRequest;

/**
* <p>
* socket消息发送表 前端控制器
* </p>
* @author xujun
* @since 2020-08-28
*/


@Api(tags = "socket消息发送表控制器")
@RequestMapping("/socketMsg")
@RestController
public class SocketMsgController{


    SocketMsgService socketMsgService;

    @Autowired
    private SocketMsgMapper socketMsgMapper;
    @Autowired
    public  SocketMsgController(SocketMsgService socketMsgService){
        this.socketMsgService = socketMsgService;
    }

    /**
    * <p>
        * 根据条件查询全部记录（并翻页）
        * </p>
    */

    @ApiOperation(value = "列表查询")
    @GetMapping("/list")
    public JsonResult<IPage<SocketMsg>> list(int pageNum, int pageSize, HttpServletRequest request) {
     /*   QueryWrapper<SocketMsg> queryWrapper = new QueryWrapper<SocketMsg>();
        queryWrapper.eq("notary_id",socketMsgService.getNotaryId(request));
        queryWrapper.eq("flag",0);*/
        SocketMsg socketMsg=new SocketMsg();
        socketMsg.setReceive(socketMsgService.getNotaryId(request).longValue());
        Page<SocketMsg> page = new Page<SocketMsg>(pageNum,pageSize);
        IPage<SocketMsg> iPage = socketMsgMapper.getMySocket(page,socketMsg);
        return JsonResult.success(iPage);
    }


    /**
        *<P>
        * 根据ID查找返回单个对象
        *</P>
    */
    @ApiOperation(value = "根据id修改消息通知")
    @GetMapping("/updateFlagBy/{id}")
    public JsonResult<SocketMsg> getById(@PathVariable("id") Integer id) {
        socketMsgService.updateFlagBy(id);
         return JsonResult.success();
    }


    /**
        *<p>
        * 保存对象-如果对象存在则修改原数据，否则插入一条新数据
        *</p>
    */
    @ApiOperation(value = "保存对象")
    @GetMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody SocketMsg socketMsg) {
        return JsonResult.success(socketMsgService.saveOrUpdate(socketMsg));
    }


    /**
        *<p>
        * 根据 id删除记录-逻辑删除
        *</p>
    */
    @ApiOperation(value = "删除")
    @GetMapping("/remove/{id}")
    public JsonResult removeById(@PathVariable("id") Integer id) {
        return JsonResult.success(socketMsgService.removeById(id));
    }


}

                       